public final class ItemDefinition {
	public static int totalItems;
	public static Packet buffer;
	public static ItemDefinition[] cache;
	public static int cacheIndex;
	public static boolean isMembers = true;
	static Cache spriteCache = new Cache(100);
	public static Cache modelCache = new Cache(50);
	public static int[] streamIndices;
	/**
	 * aByte154
	 */
	public byte femaleEquipOffset;
	/**
	 * aByte205
	 */
	public byte maleEquipOffset;
	public String actions[];
	/**
	 * anInt162
	 */
	public int femaleEmblem;
	public int anInt164;
	public int anInt166;
	/**
	 * anInt167
	 */
	public int scaleX;
	/**
	 * anInt173
	 */
	public int scaleTriangles;
	public int anInt175;
	/**
	 * anInt184
	 */
	public int shadowing;
	/**
	 * anInt185
	 */
	public int maleEmblem;
	public int anInt188;
	/**
	 * anInt191
	 */
	public int scaleY;
	/**
	 * anInt192
	 */
	public int scaleZ;
	/**
	 * anInt196
	 */
	public int brightness;
	public int anInt197;
	public int anInt199;
	public int anInt204;
	public int certID;
	public int certTemplateID;
	public byte description[];
	public int femaleEquip1;
	public int femaleEquip2;
	public String groundActions[];
	public int itemID;
	public int maleEquip1;
	public int maleEquip2;
	public boolean membersObject;
	public int groundModel;
	/**
	 * modelOffset1
	 */
	public int offsetX;
	/**
	 * modelOffset2
	 */
	public int offsetY;
	/**
	 * modelRotation1
	 */
	public int rotationY;
	/**
	 * modelRotation2
	 */
	public int rotationX;
	public int zoom;
	public int[] modifiedColors;
	public String name;
	public int[] originalColors;
	public boolean stackable;
	public int[] stackAmounts;
	public int[] stackIDs;
	public int team;
	public int value;

	public static ItemDefinition forID(int i) {
		for (int j = 0; j < 10; j++) {
			if (ItemDefinition.cache[j].itemID == i) {
				return ItemDefinition.cache[j];
			}
		}
		ItemDefinition.cacheIndex = (ItemDefinition.cacheIndex + 1) % 10;
		ItemDefinition itemDefinition = ItemDefinition.cache[ItemDefinition.cacheIndex];
		ItemDefinition.buffer.offset = ItemDefinition.streamIndices[i];
		itemDefinition.itemID = i;
		itemDefinition.setDefaults();
		itemDefinition.readValues(ItemDefinition.buffer);
		if (itemDefinition.certTemplateID != -1) {
			itemDefinition.toNote();
		}
		if (!ItemDefinition.isMembers && itemDefinition.membersObject) {
			itemDefinition.name = "Members Object";
			itemDefinition.description = "Login to a members' server to use this object."
			.getBytes();
			itemDefinition.groundActions = null;
			itemDefinition.actions = null;
			itemDefinition.team = 0;
		}
		if (i == 1042) {
			itemDefinition.femaleEquipOffset = 0;
			itemDefinition.maleEquipOffset = 0;
			itemDefinition.actions = new String[5];
			itemDefinition.actions[1] = "Wear";
			itemDefinition.femaleEmblem = -1;
			itemDefinition.anInt164 = 0;
			itemDefinition.anInt166 = -1;
			itemDefinition.scaleX = 128;
			itemDefinition.scaleTriangles = -1;
			itemDefinition.anInt175 = 29;
			itemDefinition.shadowing = 0;
			itemDefinition.maleEmblem = -1;
			itemDefinition.anInt188 = 0;
			itemDefinition.scaleY = 128;
			itemDefinition.scaleZ = 128;
			itemDefinition.brightness = 0;
			itemDefinition.anInt197 = 1087;
			itemDefinition.anInt199 = 0;
			itemDefinition.anInt204 = 0;
			itemDefinition.certID = -1;
			itemDefinition.certTemplateID = -1;
			itemDefinition.description = "A nice hat from a cracker.".getBytes();
			itemDefinition.femaleEquip1 = 363;
			itemDefinition.femaleEquip2 = -1;
			itemDefinition.maleEquip1 = 187;
			itemDefinition.maleEquip2 = -1;
			itemDefinition.membersObject = false;
			itemDefinition.groundModel = 2635;
			itemDefinition.offsetX = 1;
			itemDefinition.offsetY = 1;
			itemDefinition.rotationY = 76;
			itemDefinition.rotationX = 1852;
			itemDefinition.zoom = 440;
			itemDefinition.modifiedColors = new int[1];
			itemDefinition.modifiedColors[0] = 43968;
			itemDefinition.name = "Blue partyhat";
			itemDefinition.originalColors = new int[1];
			itemDefinition.originalColors[0] = 926;
			itemDefinition.stackable = false;
			itemDefinition.team = 0;
			itemDefinition.value = 1;
		}
		return itemDefinition;
	}

	public static Sprite getSprite(int i, int j, int k) {
		if (k == 0) {
			Sprite sprite = (Sprite) ItemDefinition.spriteCache.get(i);
			if ((sprite != null) && (sprite.trimHeight != j) && (sprite.trimHeight != -1)) {
				sprite.unlink();
				sprite = null;
			}
			if (sprite != null) {
				return sprite;
			}
		}
		ItemDefinition itemDefinition = ItemDefinition.forID(i);
		if (itemDefinition.stackIDs == null) {
			j = -1;
		}
		if (j > 1) {
			int i1 = -1;
			for (int j1 = 0; j1 < 10; j1++) {
				if ((j >= itemDefinition.stackAmounts[j1])
				&& (itemDefinition.stackAmounts[j1] != 0)) {
					i1 = itemDefinition.stackIDs[j1];
				}
			}
			if (i1 != -1) {
				itemDefinition = ItemDefinition.forID(i1);
			}
		}
		Model model = itemDefinition.method201(1);
		if (model == null) {
			return null;
		}
		Sprite sprite = null;
		if (itemDefinition.certTemplateID != -1) {
			sprite = ItemDefinition.getSprite(itemDefinition.certID, 10, -1);
			if (sprite == null) {
				return null;
			}
		}
		Sprite sprite2 = new Sprite(32, 32);
		int k1 = Renderer3D.middleX;
		int l1 = Renderer3D.middleY;
		int ai[] = Renderer3D.lineOffsets;
		int ai1[] = Renderer2D.pixels;
		int i2 = Renderer2D.width;
		int j2 = Renderer2D.height;
		int k2 = Renderer2D.topX;
		int l2 = Renderer2D.bottomX;
		int i3 = Renderer2D.topY;
		int j3 = Renderer2D.bottomY;
		Renderer3D.colorRestricted = false;
		Renderer2D.init(32, 32, sprite2.pixels);
		Renderer2D.fillRectangle(0, 0, 32, 32, 0);
		Renderer3D.method364();
		int k3 = itemDefinition.zoom;
		if (k == -1) {
			k3 = (int) (k3 * 1.5D);
		}
		if (k > 0) {
			k3 = (int) (k3 * 1.04D);
		}
		int l3 = Renderer3D.sineTable[itemDefinition.rotationY] * k3 >> 16;
		int i4 = Renderer3D.cosineTable[itemDefinition.rotationY] * k3 >> 16;
		model.method482(itemDefinition.rotationX, itemDefinition.anInt204,
		itemDefinition.rotationY, itemDefinition.offsetX, l3 + model.modelHeight / 2
		+ itemDefinition.offsetY, i4 + itemDefinition.offsetY);
		for (int i5 = 31; i5 >= 0; i5--) {
			for (int j4 = 31; j4 >= 0; j4--) {
				if (sprite2.pixels[i5 + j4 * 32] == 0) {
					if ((i5 > 0) && (sprite2.pixels[(i5 - 1) + j4 * 32] > 1)) {
						sprite2.pixels[i5 + j4 * 32] = 1;
					} else if ((j4 > 0) && (sprite2.pixels[i5 + (j4 - 1) * 32] > 1)) {
						sprite2.pixels[i5 + j4 * 32] = 1;
					} else if ((i5 < 31) && (sprite2.pixels[i5 + 1 + j4 * 32] > 1)) {
						sprite2.pixels[i5 + j4 * 32] = 1;
					} else if ((j4 < 31) && (sprite2.pixels[i5 + (j4 + 1) * 32] > 1)) {
						sprite2.pixels[i5 + j4 * 32] = 1;
					}
				}
			}
		}
		if (k > 0) {
			for (int j5 = 31; j5 >= 0; j5--) {
				for (int k4 = 31; k4 >= 0; k4--) {
					if (sprite2.pixels[j5 + k4 * 32] == 0) {
						if ((j5 > 0) && (sprite2.pixels[(j5 - 1) + k4 * 32] == 1)) {
							sprite2.pixels[j5 + k4 * 32] = k;
						} else if ((k4 > 0) && (sprite2.pixels[j5 + (k4 - 1) * 32] == 1)) {
							sprite2.pixels[j5 + k4 * 32] = k;
						} else if ((j5 < 31) && (sprite2.pixels[j5 + 1 + k4 * 32] == 1)) {
							sprite2.pixels[j5 + k4 * 32] = k;
						} else if ((k4 < 31) && (sprite2.pixels[j5 + (k4 + 1) * 32] == 1)) {
							sprite2.pixels[j5 + k4 * 32] = k;
						}
					}
				}
			}
		} else if (k == 0) {
			for (int k5 = 31; k5 >= 0; k5--) {
				for (int l4 = 31; l4 >= 0; l4--) {
					if ((sprite2.pixels[k5 + l4 * 32] == 0) && (k5 > 0) && (l4 > 0)
					&& (sprite2.pixels[(k5 - 1) + (l4 - 1) * 32] > 0)) {
						sprite2.pixels[k5 + l4 * 32] = 0x302020;
					}
				}
			}
		}
		if (itemDefinition.certTemplateID != -1) {
			int l5 = sprite.trimWidth;
			int j6 = sprite.trimHeight;
			sprite.trimWidth = 32;
			sprite.trimHeight = 32;
			sprite.drawSprite(0, 0);
			sprite.trimWidth = l5;
			sprite.trimHeight = j6;
		}
		if (k == 0) {
			ItemDefinition.spriteCache.put(sprite2, i);
		}
		Renderer2D.init(i2, j2, ai1);
		Renderer2D.setDrawingArea(k2, i3, l2, j3);
		Renderer3D.middleX = k1;
		Renderer3D.middleY = l1;
		Renderer3D.lineOffsets = ai;
		Renderer3D.colorRestricted = true;
		if (itemDefinition.stackable) {
			sprite2.trimWidth = 33;
		} else {
			sprite2.trimWidth = 32;
		}
		sprite2.trimHeight = j;
		return sprite2;
	}

	public static void nullLoader() {
		ItemDefinition.modelCache = null;
		ItemDefinition.spriteCache = null;
		ItemDefinition.streamIndices = null;
		ItemDefinition.cache = null;
		ItemDefinition.buffer = null;
	}

	public static void unpackConfig(Archive archive) {
		ItemDefinition.buffer = new Packet(archive.getFile("obj.dat"));
		Packet buffer = new Packet(archive.getFile("obj.idx"));
		ItemDefinition.totalItems = buffer.getUnsignedShort();
		ItemDefinition.streamIndices = new int[ItemDefinition.totalItems + Short.MAX_VALUE];
		int i = 2;
		for (int j = 0; j < ItemDefinition.totalItems; j++) {
			ItemDefinition.streamIndices[j] = i;
			i += buffer.getUnsignedShort();
		}
		ItemDefinition.cache = new ItemDefinition[10];
		for (int k = 0; k < 10; k++) {
			ItemDefinition.cache[k] = new ItemDefinition();
		}
	}

	public void actionData(int a, String b) {
		actions = new String[5];
		actions[a] = b;
	}

	public void colors(int id, int original, int modified) {
		originalColors[id] = original;
		modifiedColors[id] = modified;
	}

	public void itemData(String n, String d) {
		name = n;
		description = d.getBytes();
	}

	public boolean method192(int j) {
		int k = anInt175;
		int l = anInt166;
		if (j == 1) {
			k = anInt197;
			l = scaleTriangles;
		}
		if (k == -1) {
			return true;
		}
		boolean flag = true;
		if (!Model.method463(k)) {
			flag = false;
		}
		if ((l != -1) && !Model.method463(l)) {
			flag = false;
		}
		return flag;
	}

	public Model method194(int j) {
		int k = anInt175;
		int l = anInt166;
		if (j == 1) {
			k = anInt197;
			l = scaleTriangles;
		}
		if (k == -1) {
			return null;
		}
		Model model = Model.method462(k);
		if (l != -1) {
			Model model_1 = Model.method462(l);
			Model models[] = { model, model_1 };
			model = new Model(2, models);
		}
		if (originalColors != null) {
			for (int i1 = 0; i1 < originalColors.length; i1++) {
				model.method476(originalColors[i1], modifiedColors[i1]);
			}
		}
		return model;
	}

	public boolean method195(int j) {
		int k = maleEquip1;
		int l = maleEquip2;
		int i1 = maleEmblem;
		if (j == 1) {
			k = femaleEquip1;
			l = femaleEquip2;
			i1 = femaleEmblem;
		}
		if (k == -1) {
			return true;
		}
		boolean flag = true;
		if (!Model.method463(k)) {
			flag = false;
		}
		if ((l != -1) && !Model.method463(l)) {
			flag = false;
		}
		if ((i1 != -1) && !Model.method463(i1)) {
			flag = false;
		}
		return flag;
	}

	public Model method196(int i) {
		int j = maleEquip1;
		int k = maleEquip2;
		int l = maleEmblem;
		if (i == 1) {
			j = femaleEquip1;
			k = femaleEquip2;
			l = femaleEmblem;
		}
		if (j == -1) {
			return null;
		}
		Model model = Model.method462(j);
		if (k != -1) {
			if (l != -1) {
				Model model_2 = Model.method462(k);
				Model model_3 = Model.method462(l);
				Model models[] = { model, model_2, model_3 };
				model = new Model(3, models);
			} else {
				Model model_2 = Model.method462(k);
				Model models[] = { model, model_2 };
				model = new Model(2, models);
			}
		}
		if ((i == 0) && (maleEquipOffset != 0)) {
			model.method475(0, maleEquipOffset, 0);
		}
		if ((i == 1) && (femaleEquipOffset != 0)) {
			model.method475(0, femaleEquipOffset, 0);
		}
		if (originalColors != null) {
			for (int i1 = 0; i1 < originalColors.length; i1++) {
				model.method476(originalColors[i1], modifiedColors[i1]);
			}
		}
		return model;
	}

	public Model method201(int i) {
		if ((stackIDs != null) && (i > 1)) {
			int j = -1;
			for (int k = 0; k < 10; k++) {
				if ((i >= stackAmounts[k]) && (stackAmounts[k] != 0)) {
					j = stackIDs[k];
				}
			}
			if (j != -1) {
				return ItemDefinition.forID(j).method201(1);
			}
		}
		Model model = (Model) ItemDefinition.modelCache.get(itemID);
		if (model != null) {
			return model;
		}
		model = Model.method462(groundModel);
		if (model == null) {
			return null;
		}
		if ((scaleX != 128) || (scaleZ != 128) || (scaleY != 128)) {
			model.method478(scaleX, scaleY, scaleZ);
		}
		if (originalColors != null) {
			for (int l = 0; l < originalColors.length; l++) {
				model.method476(originalColors[l], modifiedColors[l]);
			}
		}
		model.preProcess(64 + brightness, 768 + shadowing, -50, -10, -50, true);
		model.aBoolean1659 = true;
		ItemDefinition.modelCache.put(model, itemID);
		return model;
	}

	public Model method202(int i) {
		if ((stackIDs != null) && (i > 1)) {
			int j = -1;
			for (int k = 0; k < 10; k++) {
				if ((i >= stackAmounts[k]) && (stackAmounts[k] != 0)) {
					j = stackIDs[k];
				}
			}
			if (j != -1) {
				return ItemDefinition.forID(j).method202(1);
			}
		}
		Model model = Model.method462(groundModel);
		if (model == null) {
			return null;
		}
		if (originalColors != null) {
			for (int l = 0; l < originalColors.length; l++) {
				model.method476(originalColors[l], modifiedColors[l]);
			}
		}
		return model;
	}

	public void modelData(int mZ, int mR1, int mR2, int mO1, int mO2) {
		zoom = mZ;
		rotationY = mR1;
		rotationX = mR2;
		offsetX = mO1;
		offsetY = mO2;
	}

	public void models(int mID, int mE, int fE, int mE2, int fE2) {
		groundModel = mID;
		maleEquip1 = mE;
		femaleEquip1 = fE;
		maleEquip2 = mE2;
		femaleEquip2 = fE2;
	}

	public void readValues(Packet buffer) {
		do {
			int i = buffer.getUnsignedByte();
			if (i == 0) {
				return;
			}
			if (i == 1) {
				groundModel = buffer.getUnsignedShort();
			} else if (i == 2) {
				name = buffer.getString();
			} else if (i == 3) {
				description = buffer.getBytes();
			} else if (i == 4) {
				zoom = buffer.getUnsignedShort();
			} else if (i == 5) {
				rotationY = buffer.getUnsignedShort();
			} else if (i == 6) {
				rotationX = buffer.getUnsignedShort();
			} else if (i == 7) {
				offsetX = buffer.getUnsignedShort();
				if (offsetX > 32767) {
					offsetX -= 0x10000;
				}
			} else if (i == 8) {
				offsetY = buffer.getUnsignedShort();
				if (offsetY > 32767) {
					offsetY -= 0x10000;
				}
			} else if (i == 10) {
				buffer.getUnsignedShort();
			} else if (i == 11) {
				stackable = true;
			} else if (i == 12) {
				value = buffer.getInt();
			} else if (i == 16) {
				membersObject = true;
			} else if (i == 23) {
				maleEquip1 = buffer.getUnsignedShort();
				maleEquipOffset = buffer.getByte();
			} else if (i == 24) {
				maleEquip2 = buffer.getUnsignedShort();
			} else if (i == 25) {
				femaleEquip1 = buffer.getUnsignedShort();
				femaleEquipOffset = buffer.getByte();
			} else if (i == 26) {
				femaleEquip2 = buffer.getUnsignedShort();
			} else if ((i >= 30) && (i < 35)) {
				if (groundActions == null) {
					groundActions = new String[5];
				}
				groundActions[i - 30] = buffer.getString();
				if (groundActions[i - 30].equalsIgnoreCase("hidden")) {
					groundActions[i - 30] = null;
				}
			} else if ((i >= 35) && (i < 40)) {
				if (actions == null) {
					actions = new String[5];
				}
				actions[i - 35] = buffer.getString();
			} else if (i == 40) {
				int j = buffer.getUnsignedByte();
				originalColors = new int[j];
				modifiedColors = new int[j];
				for (int k = 0; k < j; k++) {
					originalColors[k] = buffer.getUnsignedShort();
					modifiedColors[k] = buffer.getUnsignedShort();
				}
			} else if (i == 78) {
				maleEmblem = buffer.getUnsignedShort();
			} else if (i == 79) {
				femaleEmblem = buffer.getUnsignedShort();
			} else if (i == 90) {
				anInt175 = buffer.getUnsignedShort();
			} else if (i == 91) {
				anInt197 = buffer.getUnsignedShort();
			} else if (i == 92) {
				anInt166 = buffer.getUnsignedShort();
			} else if (i == 93) {
				scaleTriangles = buffer.getUnsignedShort();
			} else if (i == 95) {
				anInt204 = buffer.getUnsignedShort();
			} else if (i == 97) {
				certID = buffer.getUnsignedShort();
			} else if (i == 98) {
				certTemplateID = buffer.getUnsignedShort();
			} else if ((i >= 100) && (i < 110)) {
				if (stackIDs == null) {
					stackIDs = new int[10];
					stackAmounts = new int[10];
				}
				stackIDs[i - 100] = buffer.getUnsignedShort();
				stackAmounts[i - 100] = buffer.getUnsignedShort();
			} else if (i == 110) {
				scaleX = buffer.getUnsignedShort();
			} else if (i == 111) {
				scaleZ = buffer.getUnsignedShort();
			} else if (i == 112) {
				scaleY = buffer.getUnsignedShort();
			} else if (i == 113) {
				brightness = buffer.getByte();
			} else if (i == 114) {
				shadowing = buffer.getByte() * 5;
			} else if (i == 115) {
				team = buffer.getUnsignedByte();
			}
		} while (true);
	}

	public void setDefaults() {
		groundModel = 0;
		name = null;
		description = null;
		originalColors = null;
		modifiedColors = null;
		zoom = 2000;
		rotationY = 0;
		rotationX = 0;
		anInt204 = 0;
		offsetX = 0;
		offsetY = 0;
		stackable = false;
		value = 1;
		membersObject = false;
		groundActions = null;
		actions = null;
		maleEquip1 = -1;
		maleEquip2 = -1;
		maleEquipOffset = 0;
		femaleEquip1 = -1;
		femaleEquip2 = -1;
		femaleEquipOffset = 0;
		maleEmblem = -1;
		femaleEmblem = -1;
		anInt175 = -1;
		anInt166 = -1;
		anInt197 = -1;
		scaleTriangles = -1;
		stackIDs = null;
		stackAmounts = null;
		certID = -1;
		certTemplateID = -1;
		scaleX = 128;
		scaleZ = 128;
		scaleY = 128;
		brightness = 0;
		shadowing = 0;
		team = 0;
	}

	public void toNote() {
		ItemDefinition itemDefinition = ItemDefinition.forID(certTemplateID);
		groundModel = itemDefinition.groundModel;
		zoom = itemDefinition.zoom;
		rotationY = itemDefinition.rotationY;
		rotationX = itemDefinition.rotationX;
		anInt204 = itemDefinition.anInt204;
		offsetX = itemDefinition.offsetX;
		offsetY = itemDefinition.offsetY;
		originalColors = itemDefinition.originalColors;
		modifiedColors = itemDefinition.modifiedColors;
		ItemDefinition itemDef_1 = ItemDefinition.forID(certID);
		name = itemDef_1.name;
		membersObject = itemDef_1.membersObject;
		value = itemDef_1.value;
		String s = "a";
		char c = itemDef_1.name.charAt(0);
		if ((c == 'A') || (c == 'E') || (c == 'I') || (c == 'O') || (c == 'U')) {
			s = "an";
		}
		description = ("Swap this note at any bank for " + s + " " + itemDef_1.name + ".")
		.getBytes();
		stackable = true;
	}

	public void totalColors(int total) {
		originalColors = new int[total];
		modifiedColors = new int[total];
	}

	public ItemDefinition() {
		itemID = -1;
	}
}